//
//  ViewController.m
//  横向TableView
//
//  Created by qianfeng007 on 15/8/14.
//  Copyright (c) 2015年 李金柱. All rights reserved.
//

#import "ViewController.h"
#import "HorizontalTableView.h"

@interface ViewController ()<HorizontalTableViewDelegate>
{

    HorizontalTableView *_tableView;
}
@property (nonatomic,strong) NSMutableArray *dataArray;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    
    [self createTableView];
    [self loadData];
    
}
- (void)loadData{
    self.dataArray = [[NSMutableArray alloc]init];
    for (int i = 0; i < 100; i++) {
        [self.dataArray addObject:[NSString stringWithFormat:@"👌%d",i]];
    }
    [_tableView refreshData];
}
- (void)createTableView{
    _tableView = [[HorizontalTableView alloc]initWithFrame:CGRectMake(0, 50, self.view.frame.size.width, 200)];
    _tableView.delegate = self;
    [self.view addSubview:_tableView];
}
- (NSInteger)numberOfColumnsForTableView:(HorizontalTableView *)tableView{
    return self.dataArray.count;
 
}
- (UIView *)tableView:(HorizontalTableView *)tableView viewForIndex:(NSInteger)index{
    
    UIView *view = [tableView dequeueColumnView];
    if (!view) {
        view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
        UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(40, 40, 100, 20)];
        label.tag = 100;
         [view addSubview:label];
        
    }
    
    CGFloat a = arc4random()%256/255.0;
    CGFloat b = arc4random()%256/255.0;
    CGFloat c = arc4random()%256/255.0;

    view.backgroundColor = [UIColor colorWithRed:a green:b blue:c alpha:1.0];
    
  
    UILabel *label =(UILabel *)[view viewWithTag:100];
    label.text = self.dataArray[index];

    return view;
}
- (CGFloat)columnWidthForTableView:(HorizontalTableView *)tableView{
    
    return self.view.frame.size.width;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
